package dao

import (
	"database/sql"
	"errors"
	"fmt"
)
import _ "github.com/go-sql-driver/mysql"

var DB *sql.DB

func InitDB() (err error) {
	DB, err = sql.Open("mysql", "bt_go:07ZjxQG87NTO9hUL@tcp(175.178.40.245:3309)/jingdong?charset=utf8mb4&parseTime=True")
	if err != nil {
		err = errors.New("sql.Open err")
		//fmt.Println("sql.Open err", err)
		return err
	}
	err = DB.Ping()
	if err != nil {
		err = errors.New("DB.Ping() err")
		return err
	}
	fmt.Println("DB connect successful")
	DB.SetMaxOpenConns(10)
	return err
}
